#include "Scene.h"
//#include "rapidxml.hpp"
#include "DotSceneLoader.h"
#include "MenuManager.h"

class GameScene:public Scene
{
public:
	GameScene(SceneEvnArgs evn):Scene(evn){}
	virtual void Initialization() 
	{
		Scene::Initialization();
	}

	virtual void createScene( void ) 
	{
		SelectedNumber = 0;
		ListType = -1;
		VolumeValue = 3;
		ConfirmChoice = 0;

		//Runscript("GameFrame.lua");
		CEGUI::SchemeManager::getSingleton().create("MySkin.scheme");
		CEGUI::System::getSingleton().setDefaultMouseCursor("MySkinImages", "MouseArrow");
		CEGUI::FontManager::getSingleton().create("Batang-large.font");
		fontBig = &CEGUI::FontManager::getSingleton().get("Batang-large");
		CEGUI::FontManager::getSingleton().create("Batang-small.font");
		fontSmall =  &CEGUI::FontManager::getSingleton().get("Batang-small");
		CEGUI::System::getSingleton().setDefaultFont("Batang-small");
		MenuManager::getSingleton().ActiveWindow("gameFrame.layout");

		mWmg = CEGUI::WindowManager::getSingletonPtr();

		/**
			Main
		*/
		MainList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Main");
		CEGUI::ItemEntry *MainListTop = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Top");
		MainList->addItem(MainListTop);

		Restart=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Restart");
		CEGUI::Window *RestartText=(CEGUI::Window*)mWmg->getWindow("RestartText");
		Restart->addChildWindow(RestartText);
		MainList->addItem(Restart);

		Volume=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Volume");
		CEGUI::Window *VolumeText=(CEGUI::Window*)mWmg->getWindow("VolumeText");
		Volume->addChildWindow(VolumeText);
		MainList->addItem(Volume);

		Exit=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Exit");
		CEGUI::Window *ExitText=(CEGUI::Window*)mWmg->getWindow("ExitText");
		Exit->addChildWindow(ExitText);
		MainList->addItem(Exit);

		CEGUI::ItemEntry * MainListBottom = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Bottom");
		MainList->addItem(MainListBottom);

		MainList->getVertScrollbar()->setScrollPosition(30);
		Restart->getChild("RestartText")->setFont(fontBig);
		Restart->getChild("RestartText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
		Restart->select();
		Volume->setHeight(CEGUI::UDim(0,30));
		Exit->setHeight(CEGUI::UDim(0,30));
		/**
			Restart
		*/
		RestartList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Restart");

		/**
			VolumeList
		*/
		VolumeList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Volume");

		CEGUI::ItemEntry * VolumeListTop = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","VolumeTop");
		CEGUI::ItemEntry * VolumeListBottom = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","VolumeBottom");
		
		zero = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","zero");
		zero->addChildWindow((CEGUI::Window*)mWmg->getWindow("zeroText"));
		one = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","one");
		one->addChildWindow((CEGUI::Window*)mWmg->getWindow("oneText"));
		two = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","two");
		two->addChildWindow((CEGUI::Window*)mWmg->getWindow("twoText"));
		three = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","three");
		three->addChildWindow((CEGUI::Window*)mWmg->getWindow("threeText"));
		four = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","four");
		four->addChildWindow((CEGUI::Window*)mWmg->getWindow("fourText"));
		five = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","five");
		five->addChildWindow((CEGUI::Window*)mWmg->getWindow("fiveText"));


		VolumeList->addItem(VolumeListTop);
		VolumeList->addItem(zero);
		VolumeList->addItem(one);
		VolumeList->addItem(two);
		VolumeList->addItem(three);
		VolumeList->addItem(four);
		VolumeList->addItem(five);
		VolumeList->addItem(VolumeListBottom);

		//VolumeList->setVisible(false);

		zero->setHeight(CEGUI::UDim(0,30));
		one->setHeight(CEGUI::UDim(0,30));
		two->setHeight(CEGUI::UDim(0,30));
		three->setHeight(CEGUI::UDim(0,30));
		four->setHeight(CEGUI::UDim(0,30));
		five->setHeight(CEGUI::UDim(0,30));

		switch(VolumeValue)
		{
		case 0:
			VolumeList->getVertScrollbar()->setScrollPosition(30);
			zero->getChild("zeroText")->setFont(fontBig);
			zero->getChild("zeroText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setHeight(CEGUI::UDim(0,60));
			zero->select();
			break;
		case 1:
			VolumeList->getVertScrollbar()->setScrollPosition(90);
			one->getChild("oneText")->setFont(fontBig);
			one->getChild("oneText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setHeight(CEGUI::UDim(0,60));
			one->select();
			break;
		case 2:
			VolumeList->getVertScrollbar()->setScrollPosition(150);
			two->getChild("twoText")->setFont(fontBig);
			two->getChild("twoText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
			two->setHeight(CEGUI::UDim(0,60));
			two->select();
			break;
		case 3:
			VolumeList->getVertScrollbar()->setScrollPosition(210);
			three->getChild("threeText")->setFont(fontBig);
			three->getChild("threeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
			two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,210)));
			three->setHeight(CEGUI::UDim(0,60));
			three->select();
			break;
		case 4:
			VolumeList->getVertScrollbar()->setScrollPosition(270);
			four->getChild("fourText")->setFont(fontBig);
			four->getChild("fourText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
			two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,210)));
			three->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,270)));
			four->setHeight(CEGUI::UDim(0,60));
			four->select();
			break;
		case 5:
			VolumeList->getVertScrollbar()->setScrollPosition(330);
			five->getChild("fiveText")->setFont(fontBig);
			five->getChild("fiveText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
			two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,210)));
			three->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,270)));
			four->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,330)));
			five->setHeight(CEGUI::UDim(0,60));
			five->select();
			break;
		}

		/**
			Exit
		*/
		ExitList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Exit");
		//ExitList->setVisible(false);

		//ConfirmFrame = (CEGUI::Window*)mWmg->getWindow("Root/Window/ConfirmFrame");
		//ConfirmList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/ConfirmFrame/Confirm");

		//CEGUI::ItemEntry * ConfrimListTop = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","ConfirmTop");
		//ConfirmList->addItem(ConfrimListTop);

		//Cancel=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Cancel");
		//Cancel->addChildWindow((CEGUI::Window*)mWmg->getWindow("CancelText"));
		//ConfirmList->addItem(Cancel);

		//Confirm=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Confirm");
		//Confirm->addChildWindow((CEGUI::Window*)mWmg->getWindow("ConfirmText"));
		//ConfirmList->addItem(Confirm);

		//CEGUI::ItemEntry * ConfirmListBottom = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","ConfirmBottom");
		//ConfirmList->addItem(ConfirmListBottom);

		//ConfirmList->getVertScrollbar()->setScrollPosition(30);
		//Cancel->getChild("CancelText")->setFont(fontBig);
		//Cancel->getChild("CancelText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
		//Confirm->getChild("ConfirmText")->setFont(fontSmall);
		//Confirm->getChild("ConfirmText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
		//Confirm->setHeight(CEGUI::UDim(0,30));
		//Cancel->select();

		CEGUI::PushButton *Up = (CEGUI::PushButton *)mWmg->getWindow("Root/Window/Up");
		CEGUI::PushButton *Down = (CEGUI::PushButton *)mWmg->getWindow("Root/Window/Down");
		CEGUI::PushButton *Left = (CEGUI::PushButton *)mWmg->getWindow("Root/Window/Left");
		CEGUI::PushButton *Right = (CEGUI::PushButton *)mWmg->getWindow("Root/Window/Right");

		Up->subscribeEvent(CEGUI::PushButton::EventMouseClick,CEGUI::Event::Subscriber(&GameScene::onUpClick,this));
		Down->subscribeEvent(CEGUI::PushButton::EventMouseClick,CEGUI::Event::Subscriber(&GameScene::onDownClick,this));
		Left->subscribeEvent(CEGUI::PushButton::EventMouseClick,CEGUI::Event::Subscriber(&GameScene::onLeftClick,this));
		Right->subscribeEvent(CEGUI::PushButton::EventMouseClick,CEGUI::Event::Subscriber(&GameScene::onRightClick,this));
		

		mAmg = CEGUI::AnimationManager::getSingletonPtr();
		mAmg->loadAnimationsFromXML("myAnimations.xml");

		ChangeSelection1 = mAmg->getAnimation("ChangeSelection1");
		ChangeSelectionIns1 = mAmg->instantiateAnimation(ChangeSelection1);

		ChangeSelection2 = mAmg->getAnimation("ChangeSelection2");
		ChangeSelectionIns2 = mAmg->instantiateAnimation(ChangeSelection2);

		ChangeSelectionTop = mAmg->getAnimation("ChangeSelectionTop");
		ChangeSelectionInsTop = mAmg->instantiateAnimation(ChangeSelectionTop);

		ChangeSelectionBottom = mAmg->getAnimation("ChangeSelectionBottom");
		ChangeSelectionInsBottom = mAmg->instantiateAnimation(ChangeSelectionBottom);

		ShowWindow = mAmg->getAnimation("ShowWindow");
		ShowWindowIns = mAmg->instantiateAnimation(ShowWindow);

		HideWindow = mAmg->getAnimation("HideWindow");
		HideWindowIns = mAmg->instantiateAnimation(HideWindow);

		SelectionItem = mAmg->getAnimation("SelectionItem");
		SelectionItemIns = mAmg->instantiateAnimation(SelectionItem);

		InverSelectionItem1 = mAmg->getAnimation("InverSelectionItem1");		//move down 30 pixels
		InverSelectionItem1Ins = mAmg->instantiateAnimation(InverSelectionItem1);

		InverSelectionItem2 = mAmg->getAnimation("InverSelectionItem2");
		InverSelectionItem2Ins = mAmg->instantiateAnimation(InverSelectionItem2);

		FontChange1 = mAmg->getAnimation("FontChange1");
		FontChange1Ins = mAmg->instantiateAnimation(FontChange1);

		FontChange2 = mAmg->getAnimation("FontChange2");
		FontChange2Ins = mAmg->instantiateAnimation(FontChange2);



		//RestartList->setVisible(false);
		//VolumeList->setVisible(false);
		//ExitList->setVisible(false);

		MainList->setAlpha(0);
		RestartList->setAlpha(0);
		VolumeList->setAlpha(0);
		ExitList->setAlpha(0);
		//ConfirmList->setAlpha(0);
	}

	bool onDownClick(const CEGUI::EventArgs &e)
	{
		endAnimations();
		if(ListType == 0)
		{
			if(SelectedNumber == 2)
			{
				ChangeSelectionInsBottom->setTargetWindow(MainList->getVertScrollbar());
				ChangeSelectionInsBottom->start();
			}
			else if(SelectedNumber < 2 )
			{
					ChangeSelectionIns1->setTargetWindow(MainList->getVertScrollbar());
					ChangeSelectionIns1->start();
					SelectedNumber++;
					switch(SelectedNumber)
					{
					case 0:
						Restart->select();
						break;
					case 1:
						Volume->select();
						Restart->getChild("RestartText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(Restart);
						InverSelectionItem1Ins->start();
						Volume->getChild("VolumeText")->setFont(fontBig);
						Volume->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						Volume->setHeight(CEGUI::UDim(0,60));
						Restart->getChild("RestartText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Volume->getChild("VolumeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 2:
						Exit->select();
						Volume->getChild("VolumeText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(Volume);
						InverSelectionItem1Ins->start();
						Exit->getChild("ExitText")->setFont(fontBig);
						Exit->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,180)));
						Exit->setHeight(CEGUI::UDim(0,60));
						Volume->getChild("VolumeText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Exit->getChild("ExitText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					default:
						break;
					}
			}
		}else if(ListType == 1)
		{
			/*if(SelectedNumber == 0 || SelectedNumber == 2)
			{
				if(ConfirmChoice == 1)
				{
					ChangeSelectionInsBottom->setTargetWindow(ConfirmList->getVertScrollbar());
					ChangeSelectionInsBottom->start();
				}
				else if(ConfirmChoice < 1)
				{
					ChangeSelectionIns1->setTargetWindow(ConfirmList->getVertScrollbar());
					ChangeSelectionIns1->start();
					ConfirmChoice ++;
					switch(ConfirmChoice)
					{
					case 0:
						Cancel->select();
						break;
					case 1:
						Confirm->select();
						Cancel->getChild("CancelText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(Cancel);
						InverSelectionItem1Ins->start();
						Confirm->getChild("ConfirmText")->setFont(fontBig);
						Confirm->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						Confirm->setHeight(CEGUI::UDim(0,60));
						Cancel->getChild("CancelText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Confirm->getChild("ConfirmText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					}
				}
			}
			else */if(SelectedNumber == 1)
			{
				if(VolumeValue == 5)
				{
					ChangeSelectionInsBottom->setTargetWindow(VolumeList->getVertScrollbar());
					ChangeSelectionInsBottom->start();
				}
				else if(VolumeValue < 5)
				{
					ChangeSelectionIns1->setTargetWindow(VolumeList->getVertScrollbar());
					ChangeSelectionIns1->start();
					VolumeValue++;
					switch(VolumeValue)
					{
					case 0:
						zero->select();
						break;
					case 1:
						one->select();
						zero->getChild("zeroText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(zero);
						InverSelectionItem1Ins->start();
						one->getChild("oneText")->setFont(fontBig);
						one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						one->setHeight(CEGUI::UDim(0,60));
						zero->getChild("zeroText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						one->getChild("oneText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 2:
						two->select();
						one->getChild("oneText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(one);
						InverSelectionItem1Ins->start();
						two->getChild("twoText")->setFont(fontBig);
						two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,180)));
						two->setHeight(CEGUI::UDim(0,60));
						one->getChild("oneText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						two->getChild("twoText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 3:
						three->select();
						two->getChild("twoText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(two);
						InverSelectionItem1Ins->start();
						three->getChild("threeText")->setFont(fontBig);
						three->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,240)));
						three->setHeight(CEGUI::UDim(0,60));
						two->getChild("twoText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						three->getChild("threeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 4:
						four->select();
						three->getChild("threeText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(three);
						InverSelectionItem1Ins->start();
						four->getChild("fourText")->setFont(fontBig);
						four->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,300)));
						four->setHeight(CEGUI::UDim(0,60));
						three->getChild("threeText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						four->getChild("fourText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 5:
						five->select();
						four->getChild("fourText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(four);
						InverSelectionItem1Ins->start();
						five->getChild("fiveText")->setFont(fontBig);
						five->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,360)));
						five->setHeight(CEGUI::UDim(0,60));
						four->getChild("fourText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						five->getChild("fiveText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					}
				}
			}
		}
		return true;
	}

	bool onUpClick(const CEGUI::EventArgs &e)
	{
		endAnimations();
		if(ListType == 0)
		{
			if(SelectedNumber == 0)
			{
				ChangeSelectionInsTop->setTargetWindow(MainList->getVertScrollbar());
				ChangeSelectionInsTop->start();
			}
			else if(SelectedNumber > 0 )
			{
					ChangeSelectionIns2->setTargetWindow(MainList->getVertScrollbar());
					ChangeSelectionIns2->start();
					SelectedNumber--;
					switch(SelectedNumber)
					{
					case 0:
						Restart->select();
						Volume->getChild("VolumeText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(Volume);
						InverSelectionItem2Ins->start();
						Restart->getChild("RestartText")->setFont(fontBig);
						Restart->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,60)));
						Restart->setHeight(CEGUI::UDim(0,60));
						Volume->getChild("VolumeText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Restart->getChild("RestartText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 1:
						Volume->select();
						Exit->getChild("ExitText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(Exit);
						InverSelectionItem2Ins->start();
						Volume->getChild("VolumeText")->setFont(fontBig);
						Volume->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						Volume->setHeight(CEGUI::UDim(0,60));
						Exit->getChild("ExitText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Volume->getChild("VolumeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 2:
						Exit->select();
						break;
					}
			}
		}else if(ListType == 1)
		{
			/*if(SelectedNumber == 0 || SelectedNumber == 2)
			{
				if(ConfirmChoice == 0)
				{
					ChangeSelectionInsTop->setTargetWindow(ConfirmList->getVertScrollbar());
					ChangeSelectionInsTop->start();
				}
				else if(ConfirmChoice > 0)
				{
					ChangeSelectionIns2->setTargetWindow(ConfirmList->getVertScrollbar());
					ChangeSelectionIns2->start();
					ConfirmChoice --;
					switch(ConfirmChoice)
					{
					case 0:
						Cancel->select();
						Confirm->getChild("ConfirmText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(Confirm);
						InverSelectionItem1Ins->start();
						Cancel->getChild("CancelText")->setFont(fontBig);
						Cancel->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						Cancel->setHeight(CEGUI::UDim(0,60));
						Confirm->getChild("Confirm")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Cancel->getChild("CancelText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 1:
						Confirm->select();
						break;
					}
				}
			}
			else */if(SelectedNumber == 1)
			{
				if(VolumeValue == 0)
				{
					ChangeSelectionInsTop->setTargetWindow(VolumeList->getVertScrollbar());
					ChangeSelectionInsTop->start();
				}
				else if(VolumeValue > 0)
				{
					ChangeSelectionIns2->setTargetWindow(VolumeList->getVertScrollbar());
					ChangeSelectionIns2->start();
					VolumeValue--;
					switch(VolumeValue)
					{
					case 0:
						zero->select();
						one->getChild("oneText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(one);
						InverSelectionItem2Ins->start();
						zero->getChild("zeroText")->setFont(fontBig);
						zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,60)));
						zero->setHeight(CEGUI::UDim(0,60));
						one->getChild("oneText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						zero->getChild("zeroText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 1:
						one->select();
						two->getChild("twoText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(two);
						InverSelectionItem2Ins->start();
						one->getChild("oneText")->setFont(fontBig);
						one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						one->setHeight(CEGUI::UDim(0,60));
						two->getChild("twoText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						one->getChild("oneText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 2:
						two->select();
						three->getChild("threeText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(three);
						InverSelectionItem2Ins->start();
						two->getChild("twoText")->setFont(fontBig);
						two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,180)));
						two->setHeight(CEGUI::UDim(0,60));
						three->getChild("threeText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						two->getChild("twoText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 3:
						three->select();
						four->getChild("fourText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(four);
						InverSelectionItem2Ins->start();
						three->getChild("threeText")->setFont(fontBig);
						three->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,240)));
						three->setHeight(CEGUI::UDim(0,60));
						four->getChild("fourText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						three->getChild("threeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 4:
						four->select();
						five->getChild("fiveText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(five);
						InverSelectionItem2Ins->start();
						four->getChild("fourText")->setFont(fontBig);
						four->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,300)));
						four->setHeight(CEGUI::UDim(0,60));
						five->getChild("fiveText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						four->getChild("fourText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 5:
						five->select();
						break;
					}
				}
			}
		}
		return true;
	}

	bool onLeftClick(const CEGUI::EventArgs &e)
	{
		endAnimations();
		switch(ListType)
		{
		case 0:
			ListType--;
			HideWindowIns->setTargetWindow(MainList);
			HideWindowIns->start();
			break;
		case 1:
			ListType--;
			switch(SelectedNumber)
			{
			case 0:
				HideWindowIns->setTargetWindow(RestartList);
				HideWindowIns->start();
				break;
			case 1:
				HideWindowIns->setTargetWindow(VolumeList);
				HideWindowIns->start();
				break;
			case 2:
				HideWindowIns->setTargetWindow(ExitList);
				HideWindowIns->start();
				
				break;
			}
			ShowWindowIns->setTargetWindow(MainList);
			ShowWindowIns->start();
			break;
		}
		return true;
	}

	bool onRightClick(const CEGUI::EventArgs &e)
	{
		endAnimations();
		switch(ListType)
		{
		case -1:
			ListType++;
			ShowWindowIns->setTargetWindow(MainList);
			ShowWindowIns->start();
			break;
		case 0:
			ListType++;
			HideWindowIns->setTargetWindow(MainList);
			HideWindowIns->start();
			switch(SelectedNumber)
			{
			case 0:
				//PapaBallSceneManager.getSingleton().setScene(PapaBallSceneManager.getSingleton().getCurrentSceneName());

				//ShowWindowIns->setTargetWindow(ConfirmFrame);
				//ConfirmFrame->getChild("Root/Window/ConfirmFrame/Notice")->setText("Are Sure to Restart The Game?");
				//ShowWindowIns->start();
				break;
			case 1:
				ShowWindowIns->setTargetWindow(VolumeList);
				ShowWindowIns->start();
				break;
			case 2:
				//PapaBallSceneManager.getSingleton().setScene("MainScene");

				//ShowWindowIns->setTargetWindow(ConfirmFrame);
				//ConfirmFrame->getChild("Root/Window/ConfirmFrame/Notice")->setText("Are Sure to Exit The Game?");
				//ShowWindowIns->start();
				break;
			}
			break;
		//case 1:
		//	switch(SelectedNumber)
		//	{
		//	case 0:
		//		if(ConfirmChoice == 0)
		//		{
		//			ListType -- ;
		//			HideWindowIns->setTargetWindow(ConfirmFrame);
		//			HideWindowIns->start();
		//			ShowWindowIns->setTargetWindow(MainList);
		//			ShowWindowIns->start();
		//		}
		//		else if(ConfirmChoice == 1)
		//		{
		//			PapaBallSceneManager.getSingleton().setScene(PapaBallSceneManager.getSingleton().getCurrentSceneName());
		//		}
		//		break;
		//	case 2:
		//		if(ConfirmChoice == 0)
		//		{
		//			ListType -- ;
		//			HideWindowIns->setTargetWindow(ConfirmFrame);
		//			HideWindowIns->start();
		//			ShowWindowIns->setTargetWindow(MainList);
		//			ShowWindowIns->start();
		//		}
		//		else if(ConfirmChoice == 1)
		//		{
		//			PapaBallSceneManager.getSingleton().setScene("MainScene");
		//		}
		//		break;
		//	}
		//	break;
		}
		return true;
	}

	virtual void destroyScene(void)
	{
		MenuManager::getSingleton().Deactive(false);
		destroyAnimations();
		CEGUI::WindowManager::getSingleton().destroyAllWindows();
	}

	virtual void destroyAnimations(void)
	{
		ChangeSelectionIns1->stop();
		ChangeSelectionIns2->stop();
		ChangeSelectionInsTop->stop();
		ChangeSelectionInsBottom->stop();
		ShowWindowIns->stop();
		HideWindowIns->stop();
		SelectionItemIns->stop();
		InverSelectionItem1Ins->stop();
		InverSelectionItem2Ins->stop();
		FontChange1Ins->stop();
		FontChange2Ins->stop();

		mAmg->destroyAnimationInstance(ChangeSelectionIns1);
		mAmg->destroyAnimationInstance(ChangeSelectionIns2);
		mAmg->destroyAnimationInstance(ChangeSelectionInsTop);
		mAmg->destroyAnimationInstance(ChangeSelectionInsBottom);
		mAmg->destroyAnimationInstance(ShowWindowIns);
		mAmg->destroyAnimationInstance(HideWindowIns);
		mAmg->destroyAnimationInstance(SelectionItemIns);
		mAmg->destroyAnimationInstance(InverSelectionItem1Ins);
		mAmg->destroyAnimationInstance(InverSelectionItem2Ins);
		mAmg->destroyAnimationInstance(FontChange1Ins);
		mAmg->destroyAnimationInstance(FontChange2Ins);

		mAmg->destroyAnimation(ChangeSelection1);
		mAmg->destroyAnimation(ChangeSelection2);
		mAmg->destroyAnimation(ChangeSelectionTop);
		mAmg->destroyAnimation(ChangeSelectionBottom);
		mAmg->destroyAnimation(ShowWindow);
		mAmg->destroyAnimation(HideWindow);
		mAmg->destroyAnimation(SelectionItem);
		mAmg->destroyAnimation(InverSelectionItem1);
		mAmg->destroyAnimation(InverSelectionItem2);
		mAmg->destroyAnimation(FontChange1);
		mAmg->destroyAnimation(FontChange2);
	}

	void endAnimations(void)
	{
		if(ChangeSelectionIns1->isRunning())
		{
			ChangeSelectionIns1->step(0.5);
		}
		if(ChangeSelectionIns2->isRunning())
		{
			ChangeSelectionIns2->step(0.5);
		}
		if(ChangeSelectionInsTop->isRunning())
		{
			ChangeSelectionInsTop->step(0.5);
		}
		if(ChangeSelectionInsBottom->isRunning())
		{
			ChangeSelectionInsBottom->step(0.5);
		}
		if(ShowWindowIns->isRunning())
		{
			ShowWindowIns->step(0.6);
		}
		if(HideWindowIns->isRunning())
		{
			HideWindowIns->step(0.6);
		}
		if(SelectionItemIns->isRunning())
		{
			SelectionItemIns->step(0.5);
		}
		if(InverSelectionItem1Ins->isRunning())
		{
			InverSelectionItem1Ins->step(0.5);
		}
		if(InverSelectionItem2Ins->isRunning())
		{
			InverSelectionItem2Ins->step(0.5);
		}
	}
private:
	CEGUI::WindowManager *mWmg;
	CEGUI::Window *ConfirmFrame;
	CEGUI::ItemListbox *MainList,*RestartList,*VolumeList,*ExitList,*ConfirmList;
	CEGUI::ItemEntry *Restart,*Volume,*Exit,*zero,*one,*two,*three,*four,*five,*Confirm,*Cancel;
	int SelectedNumber,ListType; //ListType 0,1,2
	int VolumeValue,ConfirmChoice;

	CEGUI::AnimationManager *mAmg;
	CEGUI::Animation *ChangeSelection1,*ChangeSelection2,*ChangeSelectionTop,*ChangeSelectionBottom,
		*ShowWindow,*HideWindow,*SelectionItem,*InverSelectionItem1,*InverSelectionItem2,
		*FontChange1,*FontChange2;
	CEGUI::AnimationInstance *ChangeSelectionIns1,*ChangeSelectionIns2,*ChangeSelectionInsTop,*ChangeSelectionInsBottom,
		*ShowWindowIns,*HideWindowIns,*SelectionItemIns,*InverSelectionItem1Ins,*InverSelectionItem2Ins,
		*FontChange1Ins,*FontChange2Ins;
	CEGUI::Font *fontSmall,*fontBig;

};